﻿//-------------------------------------------------------------------------------------------------
// <copyright file="StockModel.cs" company="Kroll Bond Rating Agency, Inc.">
//  Copyright (c) Kroll Bond Rating Agency, Inc.  All rights reserved.
// </copyright>
//-------------------------------------------------------------------------------------------------

namespace StockQuoteWebSite.Models
{
    using System;
    using System.Collections.Generic;
    using System.Linq;

    /// <summary>
    /// The information displayed for a given stock.
    /// </summary>
    public class StockModel
    {
        /// <summary>
        /// Gets or sets the ticker symbol of the stock.
        /// </summary>
        public string TickerSymbol { get; set; }

        /// <summary>
        /// Gets or sets the stock's company name.
        /// </summary>
        public string CompanyName { get; set; }

        /// <summary>
        /// Gets or sets the last price at which the stock traded.
        /// </summary>
        public decimal LastPrice { get; set; }

        /// <summary>
        /// Gets or sets the first date of the range for which historical prices are available.
        /// </summary>
        public DateTime HistoricalPricesStartDate { get; set; }

        /// <summary>
        /// Gets or sets the last date of the range for which historical prices are available.
        /// </summary>
        public DateTime HistoricalPricesEndDate { get; set; }

        /// <summary>
        /// Gets or sets an <see cref="IDictionary{TKey,TValue}"/> containing points in time
        /// represented as seconds since the Unix epoch (Jan 1 1970 00:00:00 UTC) and the
        /// corresponding closing price of the stock for the day on which that period falls.
        /// </summary>
        public IDictionary<long, decimal> HistoricalPrices { get; set; }

        /// <summary>
        /// Gets a JavaScript array representation of <see cref="StockModel.HistoricalPrices"/>.
        /// </summary>
        public string HistoricalPricesJsonString
        {
            get
            {
                if (this.HistoricalPrices == null)
                {
                    return null;
                }

                var entries = this.HistoricalPrices.Select(d =>
                    "[" + d.Key + "," + d.Value + "]");

                return string.Join(",", entries);
            }
        }
    }
}